home *** CD-ROM | disk | FTP | other *** search
- /* strtok.c From TC Bible page 301 Use strtok to get the next token, or
- substring, in a string delimited by any character from a second string */
-
- #include <stdio.h>
- #include <string.h>
- char tokensep[] = " \t,";
-
- main()
- {
- int i = 0;
- char buf[80], *token;
- printf("Enter a string of tokens separated by comma or blank: ");
- gets(buf);
- token = strtok(buf, tokensep); /* Call strtok once to get first
- token and initialize it */
- while(token != NULL) /* Keep calling strtok to get all tokens */
- {
- i++;
- printf("Token %d = %s\n", i, token);
- token = strtok(NULL, tokensep);
- }
- }